package controller.servlet.category;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Category;
import controller.dao.Dao_Category;

public class EditCategory extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int codigo = Integer.parseInt(request.getParameter("cod"));
		//PrintWriter out = response.getWriter();
		Dao_Category daoe = new Dao_Category();
		Category c = daoe.list(codigo);
		request.setAttribute("cat", c);
		RequestDispatcher out = request.getRequestDispatcher("/admin/register-category.jsp");
		out.forward(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		int codigo = Integer.parseInt(request.getParameter("cod"));
		Dao_Category daoe = new Dao_Category();
		Category c = daoe.list(codigo);
		
		String name = request.getParameter("name");
		
		c.setName(name);
	
		
		daoe.save(c);
		
		response.sendRedirect("/ShoppingCart.Com_V6/admin/category.ja");
		
	}

}
